package com.wanxi.controller;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.TeacherService;
import com.wanxi.vo.TeacherVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/teacher")
@CrossOrigin(origins = "http://localhost:8081")
public class TeacherController {
    @Autowired
    TeacherService teacherService;

    @PutMapping("/add")
    public String addTeacher(TeacherVO teacherVO){
        ResultDTO resultDTO = teacherService.addTeacher(teacherVO);
        return JSONObject.toJSONString(resultDTO);
    }

    @DeleteMapping("/delete")
    public String deleteTeacher(TeacherVO teacherVO){
        ResultDTO resultDTO = teacherService.delete(teacherVO);
        return JSONObject.toJSONString(resultDTO);
    }

    @GetMapping("/findAll")
    public String findAllTeacher(){
        ResultDTO allTeacher = teacherService.findAllTeacher();
        return JSONObject.toJSONString(allTeacher);
    }

    @PostMapping("/findById")
    public String findTeacherById(TeacherVO teacherVO){
        ResultDTO teacherById = teacherService.findTeacherById(teacherVO);
        return JSONObject.toJSONString(teacherById);
    }

    @PostMapping("/updateEnable")
    public String updateTeacherEnable(TeacherVO teacherVO){
        ResultDTO resultDTO = teacherService.updateEnable(teacherVO);
        return JSONObject.toJSONString(resultDTO);
    }

    @PostMapping("/update")
    public String updateTeacher(TeacherVO teacherVO){
        ResultDTO resultDTO = teacherService.update(teacherVO);
        return JSONObject.toJSONString(resultDTO);
    }
}
